package com.md.util;

import com.google.common.collect.Lists;
import com.md.base.BaseClient;
import com.md.model.request.DeepSeekMessageRequest;
import com.md.model.request.DeepSeekRequest;
import com.md.model.response.DeepSeekResponse;
import com.md.value.DeepSeekRoleEnum;
import lombok.experimental.UtilityClass;
import org.springframework.http.HttpHeaders;

import java.util.List;

@UtilityClass
public class AiUtils {
  private BaseClient baseClient;

  public BaseClient getBaseClient() {
    if (ObjectUtil.isEmpty(baseClient)) {
      baseClient = SpringContextUtil.getBean(BaseClient.class);
    }
    return baseClient;
  }

  public DeepSeekResponse checkDiff(final String diff) {
    DeepSeekRequest deepSeekRequest = new DeepSeekRequest();
    deepSeekRequest.setModel("deepseek-chat");

    deepSeekRequest.setStream(false);
    List<DeepSeekMessageRequest> list = Lists.newArrayList();

    DeepSeekMessageRequest deepSeekMessageRequest = new DeepSeekMessageRequest();
    DeepSeekMessageRequest deepSeekMessageRequest1 = new DeepSeekMessageRequest();


    deepSeekMessageRequest.setRole(DeepSeekRoleEnum.user);
    deepSeekMessageRequest1.setRole(DeepSeekRoleEnum.user);
    deepSeekMessageRequest.setContent("解析这段Java代码的git差异, 生成代码质量得分(100分)和给出优化方案");
    deepSeekMessageRequest1.setContent(diff);

    list.add(deepSeekMessageRequest);
    list.add(deepSeekMessageRequest1);

    deepSeekRequest.setMessages(list);

    HttpHeaders httpHeaders = getBaseClient().buildHeaders();
    httpHeaders.add("Authorization", "Bearer sk-cf85da75148548a4b97710a70f33442b");
    return getBaseClient().post("https://api.deepseek.com/chat/completions", deepSeekRequest, httpHeaders,
      DeepSeekResponse.class);
  }

}
